//
//  AppDelegate.m
//  AQBPolice
//
//  Created by apple on 2017/7/3.
//  Copyright © 2017年 eight. All rights reserved.
//

#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate ()<UNUserNotificationCenterDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 设置应用程序的图标右上角的数字
    [application setApplicationIconBadgeNumber:0];
    //进行用户权限的申请
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:UNAuthorizationOptionBadge|UNAuthorizationOptionSound|UNAuthorizationOptionAlert|UNAuthorizationOptionCarPlay completionHandler:^(BOOL granted, NSError * _Nullable error) {
        //在block中会传入布尔值granted，表示用户是否同意
        if (granted) {
            //如果用户权限申请成功，设置通知中心的代理
            [UNUserNotificationCenter currentNotificationCenter].delegate = self;
        }
    }];
    
    //初始化百度地图SDK秘钥
    _mapManager = [[BMKMapManager alloc]init];
    [_mapManager start:@"Z2lLEq2qyZiCrOEmiVnLcj5D0cFj34TY"  generalDelegate:nil];
    
    //保存用户的登录状态
    if (kPhoneNumber) {
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];
        self.window.rootViewController = storyBoard.instantiateInitialViewController;
        
    }
    
    
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    
    HKLogFunc;
    
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    HKLogFunc;
    //申请backgroundTask
    UIBackgroundTaskIdentifier myTask;
    myTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        // 后台任务到期执行，好像是10分钟
    }];

}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    HKLogFunc;
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    HKLogFunc;
    
    [application setApplicationIconBadgeNumber:0];
    
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    HKLogFunc;
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}



@end
